package org.cos.verifier.ui;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Checkbox;
import java.awt.Choice;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.ScrollPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;


public class PreferenceDlg extends Frame {
	String title = null;
	Label todo = null;
	PreferenceDlg me = null;
	Panel ctrl_panel;
	Panel list_panel;
	ScrollPane list_panel_wrap;
	
	Button ok_btn, cancel_btn;
	Checkbox autorun_chk, autoupdate_chk;
	
	public PreferenceDlg () {
		this.me = this;
		ok_btn = new Button("确定");
		cancel_btn = new Button("取消");
		autorun_chk = new Checkbox("开机自动启动");
		autoupdate_chk = new Checkbox("自动升级");
		
		ok_btn.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				// TODO Save Preference
			}
		});
		cancel_btn.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				// TODO Cancel Preference
			}
		});
		autorun_chk.addItemListener(new ItemListener(){
			public void itemStateChanged(ItemEvent e) {
				// TODO set auto run 
			}
		});
		autoupdate_chk.addItemListener(new ItemListener(){
			public void itemStateChanged(ItemEvent e) {
				// TODO set auto update
			}
		});
		
		ctrl_panel = new Panel();
		ctrl_panel.setLayout(new GridLayout(2,3, 5, 5));
		
		ctrl_panel.add(cancel_btn);
		ctrl_panel.add(new Label());
		ctrl_panel.add(ok_btn);
		ctrl_panel.add(new Label());
		ctrl_panel.add(new Label());
		ctrl_panel.add(new Label());

		list_panel = new Panel();
		list_panel.setLayout(new GridLayout(0, 1, 10, 10));
		
		Panel p = new Panel();
		p.setLayout(new FlowLayout());
		Choice sec_choice = new Choice();
		sec_choice.add("保密区域");
		sec_choice.add("日常使用");
		sec_choice.add("完全关闭");
		sec_choice.add("网络相关程序");
		sec_choice.add("本地文件相关程序");
		sec_choice.add("SMS相关程序");

		p.add(sec_choice);
		p.add(new Button("编辑该配置"));
		list_panel.add(p);
		list_panel.add(new Checkbox("开机自动启动"));
		list_panel.add(new Checkbox("自动更新"));
		
		list_panel_wrap = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
		list_panel_wrap.add(list_panel);
		me.add(new Label("CosVerifier首选项"));
		me.add(list_panel_wrap, BorderLayout.CENTER);
		me.add(ctrl_panel, BorderLayout.SOUTH);
		me.setSize(400, 500);
		me.addWindowListener(new FrameHandler());
	}
	
	class FrameHandler extends WindowAdapter {
		public void windowClosing(WindowEvent e) {
			me.dispose();
		}
	}

	public void display() {
		me.setVisible(true);
		
	}
}
